class Solution
{
public:
    long long maximumSumOfHeights(vector<int> &maxHeights)
    {
        int n = maxHeights.size();
        long long ans = 0;
        for (int peakPos = 0; peakPos < n; ++peakPos)
        {

            int height = maxHeights[peakPos];
            long long sum = height;
            for (int i = peakPos - 1; i >= 0; --i)
            {
                height = min(height, maxHeights[i]);
                sum += height;
            }
            height = maxHeights[peakPos];
            for (int i = peakPos + 1; i < n; ++i)
            {
                height = min(height, maxHeights[i]);
                sum += height;
            }

            ans = max(ans, sum);
        }
        return ans;
    }
};